package core.modules.developer.entity;

import core.util.WebUtil;

public class Column {
	private String javaName;
	private String name;
	private String remarks;
	private String javaType;// String Integer Long Double Float Date
	private int nullable;//是否可为null: 1可为null,0不能为null
	private int charLength;//char长度,utf-8下此长度除以3为真实字符长度
	private String verify;//验证规则
	private String formElementType;//表单元素类型 input select textarea
	private int searchFlag;//是否搜索 1搜索,0不搜索
	private String searchType;//搜索方式(= != like)值(eq,neq,like,like_right,like_left,isnull,isnotnull)
	public Column(){
		this.verify="";
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getJavaType() {
		return javaType;
	}

	public void setJavaType(String javaType) {
		this.javaType = javaType;
	}

	public Column(String name, String remarks, String javaType) {
		super();
		this.name = name;
		this.remarks = remarks;
		this.javaType = javaType;
	}

	public Column(String name, String remarks, int dataType,int nullable,int charLength) throws Exception {
		this.verify="";
		this.name = name;
		//this.javaName = name.replaceAll("_", "");
		this.javaName = WebUtil.camelCase(name);
		this.remarks = remarks;
		this.nullable=nullable;
		this.charLength=charLength;
		switch (dataType) {
		case java.sql.Types.INTEGER:
		case java.sql.Types.TINYINT:
		case java.sql.Types.SMALLINT:
			javaType = "Integer";
			break;
		case java.sql.Types.BIGINT:
			javaType = "Long";
			break;
		case java.sql.Types.DOUBLE:
			javaType = "Double";
			break;
		case java.sql.Types.FLOAT:
			javaType = "Float";
			break;
		case java.sql.Types.DATE:
		case java.sql.Types.TIME:
		case java.sql.Types.TIMESTAMP:
			javaType = "Date";
			break;
		case java.sql.Types.CHAR:
		case java.sql.Types.VARCHAR:
		case java.sql.Types.LONGVARCHAR:
		case java.sql.Types.NCHAR:
		case java.sql.Types.NVARCHAR:
		case java.sql.Types.LONGNVARCHAR:
			javaType = "String";
			break;
		default:
			System.out.println("未处理:dataType="+dataType);
			throw new Exception("未处理类型:dataType="+dataType+",查看java.sql.Types");
		}
	}

	public String getJavaName() {
		return javaName;
	}

	public void setJavaName(String javaName) {
		this.javaName = javaName;
	}

	public int getNullable() {
		return nullable;
	}

	public void setNullable(int nullable) {
		this.nullable = nullable;
	}

	public int getCharLength() {
		return charLength;
	}

	public void setCharLength(int charLength) {
		this.charLength = charLength;
	}

	public String getVerify() {
		return verify;
	}

	public void setVerify(String verify) {
		if (verify!=null) {
		verify=verify.replace(",", "|");
		}
		this.verify = verify;
	}

	public String getFormElementType() {
		return formElementType;
	}

	public void setFormElementType(String formElementType) {
		this.formElementType = formElementType;
	}

	public int getSearchFlag() {
		return searchFlag;
	}

	public void setSearchFlag(int searchFlag) {
		this.searchFlag = searchFlag;
	}
	public String getSearchType() {
		return searchType;
	}
	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}
}